﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ActivationCodeGenerator
{
    public partial class FormActivationCode : Form
    {
        public FormActivationCode()
        {
            InitializeComponent();
        }

        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            string userName = textBoxWikiUserName.Text;
            string trailName = textBoxTrailName.Text;

            textBoxActCode.Text = GenerateActivationCode(userName, trailName).ToString();
        }

        private long GenerateActivationCode(string userName, string trailName)
        {
            long userNameHash1 = Math.Abs(userName.GetHashCode() % 2521);
            long userNameHash2 = Math.Abs(userName.GetHashCode() % 1871);
            long userNameHash3 = Math.Abs(userName.GetHashCode() % 2069);
            long userNameHash4 = Math.Abs(userName.GetHashCode() % 2521);

            long trailNameHash1 = Math.Abs(trailName.GetHashCode() % 3391);
            long trailNameHash2 = Math.Abs(trailName.GetHashCode() % 2689);
            long trailNameHash3 = Math.Abs(trailName.GetHashCode() % 2663);
            long trailNameHash4 = Math.Abs(trailName.GetHashCode() % 3391);

            long result1 = userNameHash1 * trailNameHash4;
            long result2 = userNameHash2 * trailNameHash3;
            long result3 = userNameHash4 * trailNameHash1;
            long result4 = userNameHash3 * trailNameHash2;

            long finalResult = (result1 * (result2 % result3) * result4) % 34993499;

            return finalResult;
        }
    }
}
